package com.shensi.appCollect.utils;

import com.shensi.appCollect.utils.sequence.Sequence;

/**
 * @date 2023/8/29
 */
public class MobilePhoneUtil {

    public static final Sequence SEQUENCE = new Sequence();
    public static final String FAKE_PHONE_PREFIX = "fp";

    public static long nextId(){
        return SEQUENCE.nextId();
    }

    public static String generateFakePhone(){
        long id = SEQUENCE.nextId();
        return FAKE_PHONE_PREFIX+Long.toHexString(id);
    }

    public static boolean isFakePhone(String phone){
        return StringUtils.isBlank(phone) || StringUtils.startsWith(phone,FAKE_PHONE_PREFIX);
    }

    public static String encryPhone(String phone){
        if (StringUtils.isEmpty(phone) || phone.length()<4) {
            return phone;
        }
        String s = phone.substring(0,3)+"****";
        if (phone.length()>7) {
            s = s+phone.substring(7);
        }
        return s;
    }
}
